define(function(require,exports,module){
    if(dev) {
        console.info('加载', 'head.js');
    }
    var $=require('jquery');
    var cookie=require('lib/jquery.cookie');
    var dialog=require('lib/dialog');
    var head='<div class="content">'+
                '<a href="javascript:void(0);" onclick="window.location=\'recommend.html\'">'+
                    '<img class="logo" src="../static/images/logo.png" >'+
                '</a>'+
                '<input type="text" name="" class="search">'+
                '<a href="javascript:void(0);" class="search_button"><img src="../static/images/zoom.png" width="27px" height="27px" style="margin-left: -35px;"/></a>'+
                '<div class="right">'+
                    '<span class="username"></span>'+
                    '<ul>'+
                        '<li ><a class="recommend" href="javascript:void(0);" onclick="window.location=\'recommend.html\'"></a></li>'+
                        '<li ><a class="comment" href="news.html"></a></li>'+
                        '<li ><a class="setting" href="userinfo.html"></a></li>'+
                        '<li ><a class="fixpassword" href="setpassword.html"></a></li>'+
                        '<li ><a class="pen" href="javascript:void(0);" onclick="logout();" ></a></li>'+
                    '</ul>'+
                '</div>'+
            '</div>';
	$(".header").append(head);

    var right= '<div class="top">'+
        '<div class="content">'+
        '<p class="userlevel"><span class="username"></span></p>'+
        '<div class="number">'+
        '<a href="favorites.html">'+
        '<div class="collect">'+
        '<h3 id="account_favorite_count"></h3>'+
        '<span>Favorites</span>'+
        '</div>'+
        '</a>'+
        '<a href="download.html">'+
        '<div class="download">'+
        '<h3 id="account_download_count"></h3>'+
        '<span>Download</span>'+
        '</div>'+
        '</a>'+
        '<a href="news.html">'+
        '<div class="news">'+
        '<h3 id="account_comment_count"></h3>'+
        '<span>Messages<em class="news-num" id="account_comment_unread_count"></em></span>'+
        '</div>'+
        '</a>'+
        '</div>'+
        '</div>'+
        '</div>'+
        '<div class="rightCollection" >' +
        '<p class="title">Popular Dowload</p>'+
        //'<span class="refresh"></span>' +
        '<ul id="downhot">'+

        '</ul>'+
        '</div>'+
        '<div class="rightCollection">'+
        '<p class="title">Popular Favorites</p>'+
        '<ul id="favoritehot">'+

        '</ul>'+
        '</div>';
    $('.container>.right').append(right);

	getData('POST',interfaces.userinfo,true,'{"token":"'+$.cookie("token")+'"}','userinfo');
    getData('POST',interfaces.favorite_hot,true,'{"token":"'+$.cookie("token")+'"}','favorite_hot');
    getData('POST',interfaces.download_hot,true,'{"token":"'+$.cookie("token")+'"}','download_hot');
    getData('POST',interfaces.account_favorite_count,true,'{"token":"'+$.cookie("token")+'"}','account_favorite_count');
    getData('POST',interfaces.account_download_count,true,'{"token":"'+$.cookie("token")+'"}','account_download_count');
    getData('POST',interfaces.account_comment_count,true,'{"token":"'+$.cookie("token")+'","status":[0,2]}','account_comment_count');
    getData('POST',interfaces.account_comment_count,true,'{"token":"'+$.cookie("token")+'","status":[0]}','account_comment_unread_count');
    //给输入框绑定回车搜索事件
    //$.cookie('keyword',$(".search").val());
    $('.search').bind('keypress',function(event){
        if(event.keyCode == "13"){
            var keyword_search=$('.search').val();
            if(keyword_search==null||keyword_search==""||keyword_search==undefined){
                showDialog('Warn','keyword is black!');
                return;
            }
            $.cookie('keyword',keyword_search );
            if(dev) {
                console.info('你输入的搜索内容为：' + keyword_search);
            }
            window.location='index.html?keyword='+keyword_search;
        }
    });
    $('.search_button').bind('click',function(event){
        var keyword_search=$('.search').val();
        if(keyword_search==null||keyword_search==""||keyword_search==undefined){
            showDialog('Warn','keyword is black!');
            return;
        }
        $.cookie('keyword',keyword_search );
        if(dev) {
            console.info('你输入的搜索内容为：' + keyword_search);
        }
        window.location='index.html?keyword='+keyword_search;
    });

});


seajs.use('css/jquery.autocompleter.css');
seajs.use(['jquery','autocomplete'],function($,autocomplete){

	$(function () {
		$('.search').autocompleter({
            source: interfaces.suggest_keyword,
            limit:5,
            cache:false,
            delay:3,
            minLength:4,
            customClass: ['myClassForAutocompleter'],
            highlightMatches:true,
            //template:'<span>{{ status }} is {{ result }}</span>',
            combine:function(){
                return {
                    keyword: $(".search").val(),
                    token: $.cookie('token')
                }
            },
            callback: function (value, index) {
                if(dev) {
                    console.log("Value " + value + " are selected (with index " + index + ").");
                }
                $.cookie('keyword',value );
                window.location='index.html?keyword='+value;
            }
        });
	});
});
